<!DOCTYPE html>
<html lang="zh-cn">
<head>
{include file="public/header" /}
</head>
<body>
<div class="panel admin-panel margin-top">
  <div class="body-content">
    <form class="form-x" action="" id="cate-add" name="cate-add">
      <div class="form-group">
        <div class="label">
          <label>上级分类：</label>
        </div>
        <div class="field">
          <select id="options" class="input w50">
            <option value="0">请选择分类</option>
            {volist name="cate" id="vo"}
            <option value="{$vo.id}">{$vo.name_display}</option>
            {/volist}
          </select>
          <div class="tips">不选择上级分类默认为一级分类</div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>分类标题：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" name="name" id="title" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label>显示：</label>
        </div>
        <div class="field">
          <div class="button-group radio">        
            <input id="isshow" name="sort" type="checkbox" checked="checked">是否显示
           </div>       
        </div>
     </div>
      <div class="form-group">
        <div class="label">
          <label>排序：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" id="sort" value="0"  data-validate="number:排序必须为数字" />
          <div class="tips"></div>
        </div>
      </div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
$('#cate-add').on('submit', function (e){
  e.preventDefault();
  var title= $("#title").val();//标题
  var options=$("#options option:selected").val();//栏目
  var isshow=$("input[type='checkbox']").is(':checked');//是否显示
  var sort=$("#sort").val();//排序
  if(isshow){
    isshow=1;
  }else{
    isshow=0;
  };
  $.ajax({
  type : "POST",
  url : "{:url('houtai/cate/addajax')}",
  data:{
      'cate':title,
      'pid':options,
      'show':isshow,
      'sort':sort,
    },
    success:function(data){
      var data=eval("("+data+")");
      if (data.status) {
        parent.layer.msg("添加栏目成功！",{icon:1,time:1000,},function(){parent.location.reload();});
      }else{
        parent.layer.msg("添加栏目失败！",{icon:2,time:1000});
      }
    }
  });
});

</script>
</body>
</html>